﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Clien_Admission : System.Web.UI.Page
{
    Service.Service s;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["Student"] == null)
        {
            Response.Redirect("LoginStudent.aspx");
        }
        else
        {
            s = new Service.Service();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {


        string namestudent = Session["Student"].ToString();
        int CodeProfileStudent = s.SP_CodeProfileStudent(namestudent);
        string SchoolofYear = DropDownList2.SelectedItem.Text;
        int CodeSchoolofYear = s.CodeSchoolofYear(SchoolofYear);
        string Semester = DropDownList4.SelectedItem.Text;
        int CodeSemester = s.CodeSemester(Semester);
        string Faculty = DropDownList5.SelectedItem.Text;
        string CodeFaculty = s.CodeFaculty(Faculty);
        string SchoolSubjects = DropDownList3.SelectedItem.Text;
        int CodeSchoolSubjects = s.CodeSubjects(SchoolSubjects);
        string fullnam = TextBox2.Text;
        string date = dllThang.SelectedItem.Text + "/" + ddlNgay.SelectedItem.Text + "/" + TextBox3.Text;
        string Gender = DropDownList1.SelectedItem.Text;
        string FatherName = TextBox4.Text;
        string MotherName = TextBox1.Text;
        string ResidentalAddress = txtHokhau.Text;
        string PernamentAddress = txtAddress.Text;
        s.AddAdmission(CodeProfileStudent, CodeSchoolSubjects, CodeSchoolofYear, CodeSemester, CodeFaculty, fullnam, date, Gender, FatherName, MotherName, ResidentalAddress, PernamentAddress);
        Response.Redirect("ListAdmission.aspx");
        Response.Write("<script type='text/javascript' language='javascript'> alert('chúc mường bạn đăng ký thành công')</script>");


    }



    protected void LinkButton1_Click1(object sender, EventArgs e)
    {
        if (Session["Student"] == null)
        {
            Response.Redirect("LoginStudent.aspx");
        }
        else
        {
            Response.Redirect("ListSubject.aspx");
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (Session["Student"] == null)
        {
            Response.Redirect("LoginStudent.aspx");
        }
        else
        {
            try
            {
                //C:\Users\King\Desktop\EprojectSem3\Eproject-Sem3-Group2\Admission\
                string filename = (FileUpload1.FileName);
                FileUpload1.SaveAs(Server.MapPath(@"~\Admission\") + filename);
                Response.Write("<script type='text/javascript' language='javascript'> alert('bạn đã đăng ký thành công ')</script>");

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(@"~\Mau\AdmissionForm.doc"));

        if (file.Exists)
        {
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();
        }
        else
        {
            Response.Write("This file does not exist.");
        }
    }
}